package pfc.taller.action;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import pfc.taller.formBean.FB006_cita;
import pfc.taller.log.Log;
import pfc.taller.negocio.FuncionalidadCitas;


public class A017_administracionCitas extends DispatchAction 
{
	Logger log 					= Log.getInstance();
	FuncionalidadCitas funCita	= new FuncionalidadCitas();

	public ActionForward altaCita(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 
	{
		
		log.info("Vamos a insertar una nueva cita para el: ");
		FB006_cita formulario	= (FB006_cita)form;
		log.info(formulario.getFECHA().toString());
		
		try 
		{
			funCita.altaCita((FB006_cita)form);
		} 
		catch (SQLException e) 
		{
			log.trace("Fallo al dar de alta una nueva cita", e);
			response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		}
		
		return mapping.findForward(null);
	}
	
	public ActionForward bajaCita(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 
	{
		
		log.info("Vamos a dar de baja la cita para el: ");
		FB006_cita formulario	= (FB006_cita)form;
		log.info(formulario.getFECHA().toString());
		
		try 
		{
			funCita.bajaCita((FB006_cita)form);
		} 
		catch (Exception e) 
		{
			log.trace("Fallo al dar de baja una nueva cita", e);
			response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		}
		
		return mapping.findForward(null);
	}
}